<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>获取元素的样式值</title>
    <style>
        div {
            padding: 100px;
            width: 100px;
            height: 100px;
            background: #000;
        }
        div::after {
            width: 20px;
            height: 30px;
            background-color: #fff;
            content: "";
            display: inline-block;
        }
    </style>
</head>
<body>
    <div></div>
</body>
<script>
    // window.getComputedStyle(elem, 伪元素) 获取元素的样式表
    // 原生 getComputedStyle 的第二个参数是获取伪元素的样式表

    // 获取元素的样式值
    function getStyle(elem, prop) {
        if (window.getComputedStyle) {
            return window.getComputedStyle(elem, null)[prop];
        }else{
            return elem.currentStyle[prop];
        }
    }

    var div = document.getElementsByTagName('div')[0];
    getStyle(div, 'width');

    window.getComputedStyle(div, 'after');
</script>
</html>
